package ext.vpde.cadvaulting.util;

import java.io.PrintStream;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;
import wt.dataservice.DSProperties;
/**
 * This class is used for getting Database Connection using JDBC Driver  .
 *
 */
public class DBAccess
{

    public DBAccess()
    {
    }


/**
 * This method helps in getting Database Connection using JDBC Driver
 *
 * . DSProperties class is used to get username,password,servicename and jdbcdriver to connect to Oracle Database.
 *
 */
    public static Connection getConnection()
        throws SQLException
    {
        String s = DSProperties.DB_USER.trim();
        String s1 = DSProperties.DB_PASSWORD;
        String s2 = DSProperties.SERVICE_NAME;
        String s3 = DSProperties.JDBC_URL;
        String s4 = DSProperties.JDBC_DRIVER;
        String s5 = DSProperties.JDBC_DRIVER;
        if(!s5.equals(s4))
        {
            throw new SQLException("The JDBC driver '" + s5 + "' is not supported by " + (premigrate.common.InvalidObjectsFinder.class).getName());
        }
        Connection connection = null;
        try
        {
            DriverManager.registerDriver(new OracleDriver());
        }
        catch(SQLException sqlexception)
        {
            System.out.println("ERROR: Unable to register the jdbc driver.");
            throw sqlexception;
        }
        try
        {
            connection = DriverManager.getConnection(s3 + "@" + s2, s, s1);

        }
        catch(SQLException sqlexception1)
        {
            System.out.println("ERROR: Unable to get a connection.");
            throw sqlexception1;
        }
        return connection;
    }
}
